package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Pet;
import com.itheima.pojo.PetDesc;
import com.itheima.pojo.Result;
import com.itheima.Service.UserPetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/user/pet")
@Slf4j
public class UserPetController {
    @Autowired
    private UserPetService userPetService;

    /**
     *
     *
     * 用户端宠物分页查询
     */
    @GetMapping
    public Result selectPetPage(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                String species, Integer storeId,
                                @DateTimeFormat LocalDateTime begin,
                                @DateTimeFormat LocalDateTime end){
        PageBean pagebean = userPetService.page(page,pageSize,species,storeId,begin,end);
        return Result.success(pagebean);
    }

    /**
     * 根据id查询宠物详细信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        PetDesc pet = userPetService.selectById(id);
        return Result.success(pet);
    }

}
